using System;
using System.Collections;
using System.Collections.Generic;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using OracleInternal.Common;
using OracleInternal.Network;
using OracleInternal.TTC;
using OracleInternal.TTC.Accessors;

namespace OracleInternal.ServiceObjects
{
	internal class OracleDataReaderImpl
	{
		internal Accessor[] m_accessors;

		private OracleConnectionImpl m_connectionImpl;

		private int m_cursorId;

		private int m_rowsFetchedLastTime = -1;

		internal List<object> m_oraBufReleaseInfoList;

		internal List<OraBuf> m_tempOBList;

		internal SQLMetaData m_sqlMetaData;

		internal bool m_bForRefCursor;

		private bool m_bFetchForRefCursorFirstTime = true;

		internal long[] m_snapshotSCN;

		private bool m_bInitialLongFetchSizeModified;

		internal long m_initialLongFS;

		internal long m_clientInitialLOBFS;

		internal long m_internalInitialLOBFS;

		internal long m_internalInitialJSONFS;

		internal int m_rowsFetched;

		internal bool m_bHasMoreRowsInDB;

		private List<OracleRefCursor> m_refCursors;

		internal int m_currentRefCursorIndex;

		private CachedStatement m_cachedStmt;

		internal OracleIntervalDS m_sessionTimeZone;

		internal int m_numberOfHiddenColumns;

		internal DataUnmarshaller m_dataUnmarshaller;

		internal bool m_bPooled;

		private object m_lock = new object();

		private bool m_closed;

		internal Action OnClose;

		internal bool m_bFetching;

		internal bool m_bCancelled;

		internal void Close()
		{
			if (m_closed)
			{
				return;
			}
			lock (m_lock)
			{
				if (m_closed)
				{
					return;
				}
				m_closed = true;
				try
				{
					string commandText = null;
					if (m_sqlMetaData != null)
					{
						commandText = m_sqlMetaData.pCommandText;
					}
					ReleaseCursor(commandText);
					if (OnClose != null)
					{
						OnClose();
						OnClose = null;
					}
					if (m_refCursors != null)
					{
						for (int i = m_currentRefCursorIndex; i < m_refCursors.Count; i++)
						{
							m_refCursors[i]?.Dispose();
						}
					}
				}
				finally
				{
					if (m_connectionImpl != null)
					{
						if (m_bPooled)
						{
							m_connectionImpl.m_preferredReaderImplTaken = false;
						}
						else
						{
							m_connectionImpl.DeregisterForConnectionClose(this);
						}
					}
				}
			}
		}

		internal OracleDataReaderImpl(OracleConnectionImpl connectionImpl)
		{
			m_connectionImpl = connectionImpl;
			if (m_connectionImpl != null)
			{
				m_connectionImpl.RegisterForConnectionClose(this);
			}
		}

		internal void Init(List<OracleRefCursor> refCursors, long longFetchSize, long[] snapshotSCN)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.Init);
			}
			try
			{
				m_closed = false;
				OnClose = null;
				m_oraBufReleaseInfoList = null;
				m_accessors = null;
				m_cursorId = 0;
				m_sqlMetaData = null;
				m_cachedStmt = null;
				m_sessionTimeZone = OracleIntervalDS.Zero;
				m_clientInitialLOBFS = 0L;
				m_internalInitialLOBFS = 0L;
				m_internalInitialJSONFS = 0L;
				m_bInitialLongFetchSizeModified = false;
				m_numberOfHiddenColumns = 0;
				m_refCursors = refCursors;
				m_bForRefCursor = true;
				m_snapshotSCN = snapshotSCN;
				m_initialLongFS = longFetchSize;
				m_currentRefCursorIndex = 0;
				m_bFetchForRefCursorFirstTime = true;
				m_rowsFetchedLastTime = -1;
				m_rowsFetched = 0;
				OracleRefCursor oracleRefCursor = m_refCursors[m_currentRefCursorIndex];
				if (oracleRefCursor != null && !oracleRefCursor.IsNull)
				{
					m_bHasMoreRowsInDB = true;
					m_cursorId = oracleRefCursor.m_refCursorImpl.m_cursorId;
					oracleRefCursor.m_refCursorImpl.m_cursorId = 0;
					m_sqlMetaData = oracleRefCursor.m_refCursorImpl.m_sqlMetaData;
					m_accessors = oracleRefCursor.m_refCursorImpl.m_accessors;
					m_sessionTimeZone = oracleRefCursor.m_sessionTimeZone;
				}
				else
				{
					m_bHasMoreRowsInDB = false;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.Init, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.Init);
				}
			}
		}

		internal void Init(Accessor[] defineAccessors, SQLMetaData sqlMetaData, int cursorId, int noOfRowsFetched, CachedStatement cachedStmt, OracleIntervalDS sessionTimeZone, long initialLongFS, long clientInitialLOBFS, long internalInitialLOBFS, long internalInitialJSONFS, long[] snapshotSCN, bool metadataHasImplicitROWIDcolumn = false, bool bInitialLongFetchSizeModified = false)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.Init);
			}
			try
			{
				m_closed = false;
				OnClose = null;
				m_bCancelled = false;
				m_oraBufReleaseInfoList = null;
				m_bHasMoreRowsInDB = false;
				m_refCursors = null;
				m_bForRefCursor = false;
				m_currentRefCursorIndex = 0;
				m_bFetchForRefCursorFirstTime = true;
				m_accessors = defineAccessors;
				m_cursorId = cursorId;
				m_sqlMetaData = sqlMetaData;
				m_cachedStmt = cachedStmt;
				m_sessionTimeZone = sessionTimeZone;
				m_initialLongFS = initialLongFS;
				m_bInitialLongFetchSizeModified = bInitialLongFetchSizeModified;
				m_clientInitialLOBFS = clientInitialLOBFS;
				m_internalInitialLOBFS = internalInitialLOBFS;
				m_internalInitialJSONFS = internalInitialJSONFS;
				m_snapshotSCN = snapshotSCN;
				m_rowsFetchedLastTime = (m_rowsFetched = noOfRowsFetched);
				m_numberOfHiddenColumns = CountHiddenColumns(metadataHasImplicitROWIDcolumn);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.Init, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.Init);
				}
			}
		}

		internal static int CountHiddenColumns(bool metadataHasImplicitROWIDcolumn)
		{
			if (!metadataHasImplicitROWIDcolumn)
			{
				return 0;
			}
			return 1;
		}

		internal void ReleaseCursor(string commandText)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.ReleaseCursor);
			}
			try
			{
				if (m_cursorId == 0)
				{
					return;
				}
				if (m_connectionImpl.m_statementCache != null && m_cachedStmt != null)
				{
					if (m_bHasMoreRowsInDB)
					{
						m_connectionImpl.AddCursorIdToBeCancelled(m_cachedStmt.m_cursorId);
					}
					if (m_dataUnmarshaller != null)
					{
						DataUnmarshaller.ReleaseAllOBs(m_dataUnmarshaller.m_oraArrSegWithColRowInfo, m_dataUnmarshaller.m_oraArrSegCount, m_connectionImpl.m_oracleCommunication);
						if (m_dataUnmarshaller.m_charArrayForConversion != null)
						{
							m_connectionImpl.m_marshallingEngine.m_charArrayPooler.Enqueue(m_dataUnmarshaller.m_charArrayForConversion);
							m_dataUnmarshaller.m_charArrayForConversion = null;
						}
						m_dataUnmarshaller.m_charArrayForBigDataConversion = null;
						m_cachedStmt.m_dataUnmarshaller = m_dataUnmarshaller;
						m_dataUnmarshaller = null;
					}
					if (!string.IsNullOrWhiteSpace(commandText))
					{
						CachedStatement cachedStatement = m_connectionImpl.m_statementCache.Put(commandText, m_cachedStmt);
						if (cachedStatement != null)
						{
							m_connectionImpl.AddCursorIdToBeClosed(cachedStatement.m_cursorId);
						}
					}
				}
				else
				{
					m_connectionImpl.AddCursorIdToBeClosed(m_cursorId);
				}
				m_cursorId = 0;
				if (m_connectionImpl.m_marshallingEngine.m_oraBufRdr != null)
				{
					m_connectionImpl.m_marshallingEngine.m_oraBufRdr.FreeTempOBList();
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.ReleaseCursor, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.ReleaseCursor);
				}
			}
		}

		internal void Cancel()
		{
			m_bCancelled = true;
			if (m_bFetching)
			{
				m_connectionImpl.m_marshallingEngine.m_oracleCommunication.Break();
			}
		}

		internal int FetchMoreRows(int noOfRowsToFetch, bool fillReader, bool returnPSTypes)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.FetchMoreRows);
			}
			if (m_bCancelled)
			{
				throw new OracleException(1013, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesgWithErrCode(1013));
			}
			bool bMoreThanOneRowAffectedByDmlWithRetClause = false;
			bool flag = false;
			bool bLOBArrayFetchRequired = false;
			ColumnDescribeInfo[] columnDefines = null;
			try
			{
				bool flag2 = false;
				if (m_sqlMetaData != null && (m_sqlMetaData.HasLOBOrLongColumn || m_sqlMetaData.HasJSONColumn))
				{
					if (m_connectionImpl.m_marshallingEngine.DBVersion >= 11100 && (m_sqlMetaData.m_numOfLOBColumns > 0 || m_sqlMetaData.m_numOfJSONColumns > 0))
					{
						m_internalInitialLOBFS = TTCExecuteSql.CalculateInternalILFS(m_clientInitialLOBFS, fillReader, returnPSTypes);
						if ((m_sqlMetaData.HasLOBColumns && !fillReader && -1 == m_clientInitialLOBFS) || (fillReader && !returnPSTypes))
						{
							bLOBArrayFetchRequired = true;
						}
						if (m_cachedStmt == null || !m_cachedStmt.m_bDefinesDone || m_cachedStmt.m_internalInitialLOBFS != m_internalInitialLOBFS || m_cachedStmt.m_clientInitialLOBFS != m_clientInitialLOBFS)
						{
							flag = true;
							columnDefines = TTCExecuteSql.InitDefines(m_sqlMetaData.m_columnDescribeInfo, m_clientInitialLOBFS, m_internalInitialLOBFS, m_internalInitialJSONFS);
							if (m_cachedStmt != null)
							{
								m_cachedStmt.m_internalInitialLOBFS = m_internalInitialLOBFS;
								m_cachedStmt.m_clientInitialLOBFS = m_clientInitialLOBFS;
								m_cachedStmt.m_longFetchSize = (int)m_initialLongFS;
								m_cachedStmt.m_bDefinesDone = true;
							}
						}
					}
					else if (m_bInitialLongFetchSizeModified)
					{
						flag2 = true;
						m_bInitialLongFetchSizeModified = false;
						if (m_cachedStmt != null)
						{
							m_cachedStmt.m_longFetchSize = (int)m_initialLongFS;
						}
					}
				}
				long queryId = 0L;
				bool bDisableCompressedFetch = false;
				if (m_cachedStmt != null)
				{
					bDisableCompressedFetch = m_cachedStmt.m_bDisableCompressedFetch;
				}
				try
				{
					m_connectionImpl.m_connectionFreeToUseEvent.WaitOne();
					m_bFetching = true;
					m_connectionImpl.AddAllPiggyBackRequests(!m_bCancelled);
					TTCExecuteSql executeSqlObject = m_connectionImpl.ExecuteSqlObject;
					TTCExecuteSql.MarshalBindParameterValueHelper marshalBindParamsHelper = TTCExecuteSql.MarshalBindParameterValueHelper.Null;
					marshalBindParamsHelper.m_bWriteOutParamVal = false;
					if ((m_bForRefCursor && m_bFetchForRefCursorFirstTime) || flag || flag2)
					{
						executeSqlObject.SendExecuteRequest(null, null, bHasReturningClause: false, m_cursorId, null, 0L, columnDefines, noOfRowsToFetch, parse: false, execute: false, fetch: true, flag, bAutoCommit: false, bDisableCompressedFetch, SqlStatementType.SELECT, (int)m_initialLongFS, 0, m_snapshotSCN, ref marshalBindParamsHelper, 0);
						if (m_bForRefCursor && m_bFetchForRefCursorFirstTime)
						{
							m_bFetchForRefCursorFirstTime = false;
						}
					}
					else
					{
						m_connectionImpl.TTCFetchObject.WriteMessage(m_cursorId, noOfRowsToFetch);
					}
					long[] scnFromExecution = null;
					long[] rowsAffectedByArrayBind = null;
					List<TTCResultSet> implicitRSList = null;
					bool bDefineDone = (m_cachedStmt != null && m_cachedStmt.m_bDefinesDone) || flag;
					executeSqlObject.ReceiveExecuteResponse(ref m_accessors, null, bHasReturningParams: false, ref m_sqlMetaData, SqlStatementType.SELECT, m_rowsFetchedLastTime, noOfRowsToFetch, out m_rowsFetched, ref queryId, (int)m_initialLongFS, m_clientInitialLOBFS, m_internalInitialLOBFS, m_internalInitialJSONFS, scnFromExecution, marshalBindParamsHelper.m_bAllInBinds, 0, ref m_dataUnmarshaller, ref marshalBindParamsHelper, out rowsAffectedByArrayBind, bDefineDone, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref implicitRSList, bLOBArrayFetchRequired);
					m_rowsFetchedLastTime = m_rowsFetched;
					if (m_cachedStmt != null)
					{
						m_cachedStmt.m_numRowsFetchArrayCanAccomodate = noOfRowsToFetch;
					}
					TTCError tTCErrorObject = m_connectionImpl.m_marshallingEngine.TTCErrorObject;
					m_bHasMoreRowsInDB = true;
					if (tTCErrorObject.ErrorCode != 0)
					{
						if (tTCErrorObject.ErrorCode != 1403)
						{
							char[] t = tTCErrorObject.m_marshallingEngine.m_charArrayPooler.Dequeue();
							string errMsg = tTCErrorObject.m_marshallingEngine.m_dbCharSetConv.ConvertBytesToString(tTCErrorObject.ErrorMessage, 0, tTCErrorObject.ErrorMessage.Length, t);
							tTCErrorObject.m_marshallingEngine.m_charArrayPooler.Enqueue(ref t);
							throw new OracleException(tTCErrorObject.ErrorCode, string.Empty, string.Empty, errMsg);
						}
						m_bHasMoreRowsInDB = false;
						tTCErrorObject.Initialize();
					}
				}
				finally
				{
					m_bFetching = false;
					m_connectionImpl.m_connectionFreeToUseEvent.Set();
				}
				if (m_dataUnmarshaller != null && m_dataUnmarshaller.m_charArrayForConversion == null)
				{
					m_dataUnmarshaller.m_charArrayForConversion = m_connectionImpl.m_marshallingEngine.m_charArrayPooler.Dequeue();
				}
				return m_rowsFetched;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.FetchMoreRows, ex);
				if (ex is OracleException)
				{
					m_connectionImpl.m_lastErrorNum = ((OracleException)ex).Number;
				}
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.FetchMoreRows);
				}
			}
		}

		internal void DoLobArrayRead()
		{
			TTCLobAccessor[] array = null;
			TTCLobAccessor[] array2 = null;
			int num = 0;
			int num2 = 0;
			if (m_sqlMetaData.m_numOfCLOBCols > 0)
			{
				array = new TTCLobAccessor[m_sqlMetaData.m_numOfCLOBCols];
			}
			if (m_sqlMetaData.m_numOfBLOBCols > 0)
			{
				array2 = new TTCLobAccessor[m_sqlMetaData.m_numOfBLOBCols];
			}
			for (int i = 0; i < m_sqlMetaData.m_noOfColumns; i++)
			{
				if (m_accessors[i].m_colMetaData.m_dataType == 112)
				{
					array[num++] = (TTCLobAccessor)m_accessors[i];
				}
				else if (m_accessors[i].m_colMetaData.m_dataType == 113)
				{
					array2[num2++] = (TTCLobAccessor)m_accessors[i];
				}
			}
			if (num + num2 != m_sqlMetaData.m_numOfLOBColumns)
			{
				throw new Exception("LOB Column Count inconsistent.");
			}
			if (num > 0)
			{
				LobArrayFetch(array, num);
				if (m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList.Count > 0)
				{
					m_tempOBList = m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList;
					m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList = new List<OraBuf>();
				}
			}
			if (num2 <= 0)
			{
				return;
			}
			LobArrayFetch(array2, num2);
			if (m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList.Count > 0)
			{
				if (m_tempOBList == null)
				{
					m_tempOBList = m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList;
					m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList = new List<OraBuf>();
				}
				else
				{
					m_tempOBList.AddRange(m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList);
					m_connectionImpl.m_marshallingEngine.m_oraBufRdr.m_tempOBList.Clear();
				}
			}
		}

		internal void LobArrayFetch(TTCLobAccessor[] lobAccessors, int lobColCount)
		{
			long prefetchedDataLength = 0L;
			long dataLengthInDB = 0L;
			byte[] lobLocator = null;
			bool flag = false;
			int num = m_rowsFetched * lobColCount;
			int num2 = 0;
			int num3 = 0;
			byte[][] array = new byte[num][];
			long[] array2 = new long[num];
			long[] array3 = new long[num];
			for (int i = 0; i < m_rowsFetched; i++)
			{
				for (int j = 0; j < lobColCount; j++)
				{
					lobAccessors[j].GetLOBInfoForArrayRead(i, out prefetchedDataLength, out lobLocator, out dataLengthInDB);
					if (lobLocator != null && m_internalInitialLOBFS < dataLengthInDB)
					{
						flag = true;
						num3++;
						array[num2] = lobLocator;
						array2[num2] = dataLengthInDB - m_internalInitialLOBFS;
						array3[num2] = m_internalInitialLOBFS + 1;
					}
					else
					{
						array[num2] = null;
						array2[num2] = -1L;
						array3[num2] = -1L;
					}
					num2++;
				}
			}
			if (flag)
			{
				TTCClob tTCClob = new TTCClob(m_connectionImpl.m_marshallingEngine);
				try
				{
					m_connectionImpl.m_connectionFreeToUseEvent.WaitOne();
					tTCClob.LobArrayRead(lobAccessors, array, array2, array3, num3, lobColCount);
				}
				finally
				{
					m_connectionImpl.m_connectionFreeToUseEvent.Set();
				}
			}
		}

		internal byte[] GetByteRepresentation(int currentRow, int columnIndex)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetByteRepresentation);
			}
			byte[] result = null;
			try
			{
				if (m_accessors[columnIndex] != null)
				{
					result = m_accessors[columnIndex].GetByteRepresentation(m_dataUnmarshaller, currentRow, columnIndex);
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetByteRepresentation, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetByteRepresentation);
				}
			}
		}

		internal byte[] GetLobLocator(int currentRow, int columnIndex)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetLobLocator);
			}
			byte[] array = null;
			try
			{
				OraType dataType = (OraType)m_accessors[columnIndex].m_colMetaData.m_dataType;
				if ((uint)(dataType - 112) <= 2u || dataType == OraType.ORA_OCIJSON)
				{
					return ((TTCLobAccessor)m_accessors[columnIndex]).GetLobLocator(currentRow);
				}
				throw new Exception("Internal Error");
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetLobLocator, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetLobLocator);
				}
			}
		}

		internal double GetDouble(int currentRow, int columnIndex, out byte[] byteRep)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetDouble);
			}
			try
			{
				return m_accessors[columnIndex].GetDouble(m_dataUnmarshaller, currentRow, columnIndex, out byteRep);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetDouble, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetDouble);
				}
			}
		}

		internal float GetFloat(int currentRow, int columnIndex, out byte[] byteRep)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetFloat);
			}
			try
			{
				return m_accessors[columnIndex].GetFloat(m_dataUnmarshaller, currentRow, columnIndex, out byteRep);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetFloat, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetFloat);
				}
			}
		}

		internal bool IsCompleteDataForLongAvailable(int currentRow, int columnIndex)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.IsCompleteDataForLongAvailable);
			}
			try
			{
				return (m_accessors[columnIndex] as TTCLongAccessor).IsCompleteDataAvailable(currentRow);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.IsCompleteDataForLongAvailable, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.IsCompleteDataForLongAvailable);
				}
			}
		}

		internal int GetColumnOrdinal(string colName)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetColumnOrdinal);
			}
			try
			{
				bool flag = false;
				if (colName.StartsWith("\"") && colName.EndsWith("\""))
				{
					flag = true;
					colName = colName.Trim('"');
				}
				int num = 0;
				int num2 = m_sqlMetaData.m_columnDescribeInfo.Length;
				for (num = 0; num < num2; num++)
				{
					if (colName.Equals(m_sqlMetaData.m_columnDescribeInfo[num].pColAlias))
					{
						return num;
					}
				}
				if (!flag)
				{
					for (num = 0; num < num2; num++)
					{
						if (colName.Equals(m_sqlMetaData.m_columnDescribeInfo[num].pColAlias, StringComparison.InvariantCultureIgnoreCase))
						{
							return num;
						}
					}
				}
				throw new IndexOutOfRangeException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.DR_INV_COL_NAME));
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetColumnOrdinal, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetColumnOrdinal);
				}
			}
		}

		internal long GetBytes(int currentRow, int columnIndex, long fieldOffset, byte[] buffer, int bufferOffset, int length, byte[] lobLocator, bool bLOBArrayReadDone, ref OracleBlobImpl tempBlobImpl)
		{
			long num = 0L;
			TTCLobAccessor tTCLobAccessor = (TTCLobAccessor)m_accessors[columnIndex];
			if (buffer == null)
			{
				if (m_connectionImpl.m_marshallingEngine.DBVersion >= 11100)
				{
					return tTCLobAccessor.GetTotalLobLengthInDB(m_dataUnmarshaller, currentRow, columnIndex, bLOBArrayReadDone);
				}
				if (lobLocator == null)
				{
					lobLocator = tTCLobAccessor.GetLobLocator(currentRow);
				}
				if (tempBlobImpl == null)
				{
					tempBlobImpl = new OracleBlobImpl(m_connectionImpl, lobLocator);
				}
				else
				{
					tempBlobImpl.m_lobLocator = lobLocator;
				}
				return tempBlobImpl.GetLength();
			}
			fieldOffset++;
			if (bLOBArrayReadDone)
			{
				return OracleBlobImpl.CopyBlobDataInBytes(currentRow, m_connectionImpl, tTCLobAccessor, fieldOffset, buffer, bufferOffset, length);
			}
			if (lobLocator == null)
			{
				lobLocator = tTCLobAccessor.GetLobLocator(currentRow);
			}
			return new OracleBlobImpl(m_connectionImpl, tTCLobAccessor, m_dataUnmarshaller, currentRow, columnIndex).Read(fieldOffset, length, bufferOffset, ref buffer);
		}

		internal long GetBytes(OracleConnection connection, int currentRow, int columnIndex, long fieldOffset, byte[] buffer, int bufferOffset, int length)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetBytes);
			}
			try
			{
				long result = 0L;
				OraType internalType = m_accessors[columnIndex].m_internalType;
				if (OraType.ORA_RAW == internalType)
				{
					result = ((buffer != null) ? (m_accessors[columnIndex] as TTCRawAccessor).GetDataInBuffer(m_dataUnmarshaller, currentRow, columnIndex, fieldOffset, buffer, bufferOffset, length) : (m_accessors[columnIndex] as TTCRawAccessor).GetDataLen(m_dataUnmarshaller, currentRow, columnIndex));
				}
				else if (OraType.ORA_OCIBFileLocator == internalType)
				{
					byte[] lobLocator = (m_accessors[columnIndex] as TTCLobAccessor).GetLobLocator(currentRow);
					OracleBFileImpl oracleBFileImpl = new OracleBFileImpl(m_connectionImpl, lobLocator);
					oracleBFileImpl.OpenFile();
					fieldOffset++;
					try
					{
						result = ((buffer == null) ? oracleBFileImpl.GetLength() : oracleBFileImpl.Read(fieldOffset, length, bufferOffset, ref buffer));
					}
					finally
					{
						oracleBFileImpl.CloseFile();
						oracleBFileImpl = null;
					}
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetBytes, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetBytes);
				}
			}
		}

		internal long GetChars(int currentRow, int columnIndex, long fieldOffset, char[] buffer, int bufferOffset, int length, byte[] lobLocator, bool bLOBArrayReadDone, ref OracleClobImpl tempClobImpl)
		{
			long num = 0L;
			if (buffer == null)
			{
				if (m_connectionImpl.m_marshallingEngine.DBVersion >= 11100)
				{
					return ((TTCLobAccessor)m_accessors[columnIndex]).GetTotalLobLengthInDB(m_dataUnmarshaller, currentRow, columnIndex, bLOBArrayReadDone);
				}
				TTCLobAccessor tTCLobAccessor = (TTCLobAccessor)m_accessors[columnIndex];
				if (lobLocator == null)
				{
					lobLocator = tTCLobAccessor.GetLobLocator(currentRow);
				}
				if (tempClobImpl == null)
				{
					tempClobImpl = new OracleClobImpl(m_connectionImpl, lobLocator, tTCLobAccessor.m_colMetaData.m_characterSetForm == 2);
				}
				else
				{
					tempClobImpl.m_lobLocator = lobLocator;
					tempClobImpl.m_clobFormOfUse = (byte)tTCLobAccessor.m_colMetaData.m_characterSetForm;
					tempClobImpl.m_isNClob = tTCLobAccessor.m_colMetaData.m_characterSetForm == 2;
				}
				return tempClobImpl.GetLength();
			}
			fieldOffset++;
			if (bLOBArrayReadDone)
			{
				return OracleClobImpl.GetClobDataInChars(currentRow, m_connectionImpl, lobLocator, (TTCLobAccessor)m_accessors[columnIndex], fieldOffset, buffer, bufferOffset, length);
			}
			TTCLobAccessor tTCLobAccessor2 = (TTCLobAccessor)m_accessors[columnIndex];
			if (lobLocator == null)
			{
				lobLocator = tTCLobAccessor2.GetLobLocator(currentRow);
			}
			return new OracleClobImpl(m_connectionImpl, tTCLobAccessor2, m_dataUnmarshaller, currentRow, columnIndex).Read(fieldOffset, length, bufferOffset, ref buffer);
		}

		internal long GetChars(OracleConnection connection, int currentRow, int columnIndex, long fieldOffset, char[] buffer, int bufferOffset, int length)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetChars);
			}
			try
			{
				long result = 0L;
				OraType internalType = m_accessors[columnIndex].m_internalType;
				if (OraType.ORA_CHAR == internalType || OraType.ORA_CHARN == internalType)
				{
					result = ((buffer != null) ? (m_accessors[columnIndex] as TTCVarcharAccessor).GetCharsFromBuffer(m_dataUnmarshaller, currentRow, columnIndex, fieldOffset, buffer, bufferOffset, length, (byte)m_accessors[columnIndex].m_colMetaData.m_characterSetForm) : (m_accessors[columnIndex] as TTCVarcharAccessor).GetCharLengthFromBuffer(m_dataUnmarshaller, currentRow, columnIndex, fieldOffset, (byte)m_accessors[columnIndex].m_colMetaData.m_characterSetForm));
				}
				else if (OraType.ORA_ROWID == internalType || OraType.ORA_UROWID == internalType)
				{
					TTCRowIdAccessor tTCRowIdAccessor = m_accessors[columnIndex] as TTCRowIdAccessor;
					if (tTCRowIdAccessor != null)
					{
						result = tTCRowIdAccessor.GetChars(m_dataUnmarshaller, currentRow, columnIndex, fieldOffset, buffer, bufferOffset, length);
					}
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetChars, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.GetChars);
				}
			}
		}

		internal bool ConfigureNextResult()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.ConfigureNextResult);
			}
			try
			{
				if (m_refCursors != null && m_currentRefCursorIndex < m_refCursors.Count)
				{
					m_refCursors[m_currentRefCursorIndex]?.Dispose();
				}
				m_currentRefCursorIndex++;
				if (m_refCursors == null || m_currentRefCursorIndex >= m_refCursors.Count)
				{
					return false;
				}
				if (m_cursorId > 0)
				{
					m_connectionImpl.AddCursorIdToBeClosed(m_cursorId);
					m_cursorId = 0;
				}
				m_bFetchForRefCursorFirstTime = true;
				m_rowsFetchedLastTime = -1;
				m_rowsFetched = 0;
				OracleRefCursor oracleRefCursor = m_refCursors[m_currentRefCursorIndex];
				if (oracleRefCursor != null && !oracleRefCursor.IsNull)
				{
					m_bHasMoreRowsInDB = true;
					m_cursorId = oracleRefCursor.m_refCursorImpl.m_cursorId;
					m_sqlMetaData = oracleRefCursor.m_refCursorImpl.m_sqlMetaData;
					m_accessors = oracleRefCursor.m_refCursorImpl.m_accessors;
					m_sessionTimeZone = oracleRefCursor.m_sessionTimeZone;
				}
				else
				{
					m_bHasMoreRowsInDB = false;
					m_cursorId = 0;
					m_sqlMetaData = null;
					m_accessors = null;
					m_sessionTimeZone = OracleIntervalDS.Null;
				}
				return true;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.ConfigureNextResult, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.ConfigureNextResult);
				}
			}
		}

		internal void CollectTempLOBsToBeFreed(int rowNumber, ArrayList tempLOBArrayList)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.CollectTempLOBsToBeFreed);
			}
			if (m_accessors != null)
			{
				for (int i = 0; i < m_accessors.Length; i++)
				{
					if (!(m_accessors[i] is TTCLobAccessor))
					{
						continue;
					}
					TTCLobAccessor tTCLobAccessor = m_accessors[i] as TTCLobAccessor;
					if (tTCLobAccessor.AbstractOrTempLOB(rowNumber))
					{
						byte[] lobLocator = tTCLobAccessor.GetLobLocator(rowNumber);
						if (lobLocator == null)
						{
							continue;
						}
						if (m_connectionImpl.TemporaryLobReferenceGet(TTCLob.GetLobIdString(lobLocator)) == null)
						{
							if (tTCLobAccessor.m_definedColumnType == OraType.ORA_OCICLobLocator)
							{
								tempLOBArrayList.Add(new OracleClobImpl(m_connectionImpl, lobLocator, bNClob: false));
							}
							else if (tTCLobAccessor.m_definedColumnType == OraType.ORA_OCIBLobLocator)
							{
								tempLOBArrayList.Add(new OracleBlobImpl(m_connectionImpl, lobLocator, bCaching: false));
							}
						}
						tTCLobAccessor.m_lobLocators[rowNumber].Clear();
					}
					else if (tTCLobAccessor.m_lobLocators[rowNumber] != null && tTCLobAccessor.m_lobLocators[rowNumber].Count > 0)
					{
						tTCLobAccessor.m_lobLocators[rowNumber].Clear();
					}
				}
			}
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleDataReaderImpl, OracleTraceFuncName.CollectTempLOBsToBeFreed);
			}
		}
	}
}
